<template>
  <div>
    <el-dialog
      top="30vh"
      width="800px"
      :show-close="false"
      :lock-scroll="true"
      :append-to-body="false"
      :destroy-on-close="true"
      :visible.sync="data_visible"
      :modal-append-to-body="false"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      @closed="dialogDestroy"
    >
      <div class="main">
        <i class="el-icon-close" @click="dialogDestroy" />
        <el-row class="row">
          <el-col :xs="3" :sm="3">
            <i class="icon el-icon-circle-check" />
          </el-col>
          <el-col :xs="21" :sm="21">
            <div class="item">
              导入成功数量条数
              <b>{{ data_complete.success_file_number }}条</b>
            </div>
          </el-col>
        </el-row>
        <el-row class="row">
          <el-col :xs="3" :sm="3">
            <i class="icon el-icon-warning-outline" />
          </el-col>
          <el-col :xs="5" :sm="5">
            <div class="item">
              导入失败数量条数
              <b>{{ data_complete.failure_file_number }}条</b>
            </div>
          </el-col>
          <el-col v-if="data_complete.failure_file_number > 0" :xs="16" :sm="16">
            <div class="item">
              导入失败数据可在下方修改，修改正确后的数据可重新提交。
              <b>
                <a :href="data_complete.failure_file_download_url">未成功导入数据下载</a>
              </b>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { ApiMMallWeb } from '@services/api';

export default {
  name: 'UploadCompleteDialogComponent',
  props: {
    query: {
      type: Object,
      default: function() {
        return {};
      }
    },
    visible: {
      type: Boolean,
      default: false
    },
    fetcher: {
      type: Function,
      default: function() {}
    }
  },
  data() {
    return {
      data_complete: {
        success_file_number: 90,
        failure_file_number: 20,
        failure_file_download_url: ''
      },
      data_visible: true
    };
  },
  computed: {
    apiMMallWeb: function() {
      return new ApiMMallWeb(this.fetcher);
    }
  },
  watch: {
    visible: {
      immediate: true,
      handler: function(val, oldVal) {
        this.data_visible = val;
      }
    }
  },
  created() {
    console.log(this.query);
    this.data_complete.success_file_number = this.query.successCount;
    this.data_complete.failure_file_number = this.query.failureCount;
  },
  methods: {
    dialogDestroy() {
      this.$emit('destroy', false);
      this.$emit('update:visible', false);
    },
    dialogClose() {
      this.data_visible = false;
    }
  }
};
</script>

<style lang="less" scoped>
/deep/ .el-dialog__header {
  display: none;
}

.row {
  line-height: 24px;
  border: solid 1px #ddd;
  padding: 15px 0;
  margin-bottom: 20px;

  &:last-child {
    margin-bottom: 0 !important;
  }

  b {
    color: #1890ff;
    font-weight: bold;
    display: block;
  }

  .icon {
    line-height: 48px;
    text-align: center;
    font-size: 48px;
    display: block;
  }

  .el-icon-circle-check {
    color: #0d0;
  }

  .el-icon-warning-outline {
    color: #f90;
  }
}

.el-icon-close {
  width: 16px;
  color: #909399;
  cursor: pointer;
  line-height: 16px;
  font-size: 16px;
  text-align: center;
  position: absolute;
  top: 4px;
  right: 4px;

  &:hover {
    color: #000;
  }
}
</style>
